﻿using System.Runtime.InteropServices;

namespace TCommunication.Model;
/// <summary>
/// 斯康达回读结构体
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi,Pack=1)]
public struct SkondaCanReadFrame
{
    /// <summary>
    /// 'S'
    /// </summary>
    public char StartByte1;
    /// <summary>
    /// 'K'
    /// </summary>
    public char StartByte2;
    /// <summary>
    /// 后面有效数据长度，包括CRC的2个字节
    /// </summary>
    public byte ValidLen;
    /// <summary>
    /// -1:未收到数据帧;  -2：chan err;  -3：通道未使能; -4：未找到对应ID的数据帧;  1:表示通过read指令返回的数据帧或;  1:表示为上传数据帧;(兼容以前LN定制)  3：表示通过查找指令返回的数据帧;
    /// </summary>
    public byte Status;
    /// <summary>
    /// CanId
    /// </summary>
    public uint CanId;
    /// <summary>
    /// Can数据
    /// </summary>
    [MarshalAs(UnmanagedType.ByValArray,SizeConst=8)]
    public byte[] Data;
    /// <summary>
    /// 从设备启动开始计时，单位us
    /// </summary>
    public ulong TimeStamp;
    /// <summary>
    /// 通道号1-4
    /// </summary>
    public byte Channel;
    /// <summary>
    /// 数据长度
    /// </summary>
    public byte DataLen;
    /// <summary>
    /// 数据结构前26字节的crc结果
    /// </summary>
    public ushort Crc;
}